study( "Dimych Oscillator V2", "DOV2 •", false, format.price, 2 )


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                           ====== TOOLTIPS ======                           //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

string TT_HARSI = "Period for the RSI calculations used to generate the"        +
                  "candles. This seperate from the RSI plot/histogram length."

string TT_PBIAS = "Smoothing feature for the OPEN of the HARSI candles."        +
                  "\n\nIncreases bias toward the prior open value which can"    +
                  " help provide better visualisation of trend strength."       +
                  "\n\n** By changing the Open values, High and Low can also"   +
                  " be distorted - however Close will remain unchanged."

string TT_SMRSI = "This option smoothes the RSI in a manner similar to HA"      +
                  " open, but uses the realtime rsi rather than the prior"      +
                  " close value."

string TT_STOCH = "Uses the RSI generated by the above settings, and as such"   +
                  " will be affected by the smoothing option."

string TT_STFIT = "Adjusts the vertical scaling of the stochastic, can help"    +
                  " to prevent distortion of other data in the channel."        +
                  "\n\nHas no impact cross conditions."

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                            ====== INPUTS ======                            //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

// -- Candle config

string GROUP_CAND = "Config » Candles"
i_lenHARSI  = input( 15,            "Length",               input.integer,  group = GROUP_CAND,
                  minval = 1, tooltip = TT_HARSI )
i_smoothing = input( 15,             "Open Smoothing",       input.integer,  group = GROUP_CAND,
                  minval = 1, maxval = 100, tooltip = TT_PBIAS )
string INLINE_COL = "Colour Pallette"
i_colUp     = input( #00e1ffb7,    "Colour Pallette  ",    input.color,    group = GROUP_CAND, inline = INLINE_COL )
i_colDown   = input( #ff0d5eab,     " ",                    input.color,    group = GROUP_CAND, inline = INLINE_COL )
i_colWick   = input( #ffffff00,    " ",                    input.color,    group = GROUP_CAND, inline = INLINE_COL )

// -- RSI plot config

string GROUP_PLOT = "Config » RSI Plot"
i_source    = input( ohlc4,         "Source",               input.source,   group = GROUP_PLOT )
i_lenRSI    = input( 10,             "Length",               input.integer,  group = GROUP_PLOT,
                  minval = 1 )
i_mode      = input( true,          "Smoothed Mode RSI?",   input.bool,     group = GROUP_PLOT,
                  tooltip = TT_SMRSI )
i_showPlot  = input( true,          "Show RSI Plot?",       input.bool,     group = GROUP_PLOT )
i_showHist  = input( true,          "Show RSI Histogram?",  input.bool,     group = GROUP_PLOT )

// -- Stochastic RSI plots config

string GROUP_STOCH = "Config » Stochastic RSI Plot"
string INLINE_STDS = "Stoch Draw States"
i_showStoch = input( true,         "Show Stochastic? ",    input.bool,     group = GROUP_STOCH, inline = INLINE_STDS,
                  tooltip = TT_STOCH )
i_ribbon    = input( true,          "Ribbon?",              input.bool,     group = GROUP_STOCH, inline = INLINE_STDS )
i_smoothK   = input( 4,             "Smoothing K",          input.integer,  group = GROUP_STOCH,
                  minval = 1 )
i_smoothD   = input( 3,             "Smoothing D",          input.integer,  group = GROUP_STOCH,
                  minval = 1 )
i_stochLen  = input( 450,            "Stochastic Length",    input.integer,  group = GROUP_STOCH,
                  minval = 1 )
i_stochFit  = input( 75,            "Stoch Scaling %",      input.integer,  group = GROUP_STOCH,
                  minval = 1, maxval = 150, tooltip = TT_STFIT )

// -- Channel OB/OS config

string GROUP_CHAN = "Config » OB/OS Boundaries"
i_upper     = input( 90,            "OB",                   input.integer,  group = GROUP_CHAN, inline = "OB",
                  minval = 1, maxval = 100 )
i_upperx    = input( 95,            "OB Extreme",           input.integer,  group = GROUP_CHAN, inline = "OB",
                  minval = 1, maxval = 100 )

i_lower     = input( 15,           "OS",                   input.integer,  group = GROUP_CHAN, inline = "OS",
                  minval = 0, maxval = 20 )
i_lowerx    = input( 10,           "OS Extreme",           input.integer,  group = GROUP_CHAN, inline = "OS",
                  minval = 0, maxval = 15 )

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                          ====== FUNCTIONS ======                           //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

//  zero median rsi helper function, just subtracts 50.
f_zrsi( _source, _length ) => rsi( _source, _length ) - 0

